﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using Newtonsoft.Json;
using Group3.MediaTool.Interface;
using Group3.MediaTool.OWIN.Model;
using Group3.MediaTool.Generator;
using Group3.MediaTool.Provider;
using System.Xml.Linq;
using Group3.MediaTool.Core;
using Group3.MediaTool.Data.IO;
using Group3.MediaTool.Data.Generator;
using System.Net.Http;
using System.Net;
using System.Reflection;
using System.ComponentModel.Composition.Hosting;
using System.IO;


namespace Group3.MediaTool.OWIN.Controller
{
    /// <summary>
    /// DisplayObjectController handles the Actions for displaying objects.
    /// </summary>
    [RoutePrefix("api/displayobject")]
    public class DisplayObjectController : ApiController
    {
        public IHttpActionResult GetAllObjects(string classType)
        {
            ObjectTypeProvider op = new ObjectTypeProvider();
            Type type = op.getClassTypeFromString(classType);

            if (type != null)
            {
                IObjectRelationModel orm = (IObjectRelationModel)Activator.CreateInstance(type);
                IEnumerable<IObjectRelationModel> ormList = orm.ReadAll();

                String test = JsonConvert.SerializeObject(ormList);

                return Ok(test);
            }
            else
            {
                return Ok();
            }
        }

        public IHttpActionResult GetAllClasses(string classes)
        {
            List<String> classList = new List<string>();

            ObjectTypeProvider op = new ObjectTypeProvider();
            var toTest = op.getAllClassTypes();
            if(toTest != null)
            {
                classList = toTest;
            }

            String test = JsonConvert.SerializeObject(classList);
            if (test.Length > 0)
            {
                return Ok(test);
            }
            else
            {
                return Ok();
            }
        }


        public IHttpActionResult GetObject(int id)
        {
            var product = "";
            if (product == null)
            {
                return NotFound();
            }
            return Ok(product);
        }
    }
}
